﻿using System.Web;
using System.Web.UI;

namespace NWN.GDY.Web
{
    /// <summary>
    /// PageBase 的摘要说明
    /// </summary>
    public class PageBase : Page
    {
        public bool IsLogin
        {
            get
            {
                if (HttpContext.Current.User != null && HttpContext.Current.User.Identity != null && !string.IsNullOrEmpty(HttpContext.Current.User.Identity.Name))
                    return HttpContext.Current.User.Identity.IsAuthenticated;
                return false;
            }
        }

        public bool IsMobile()
        {
            if (Request.UserAgent.IndexOf("ipod") > -1 || Request.UserAgent.IndexOf("ipad") > -1 || Request.UserAgent.IndexOf("android") > -1 || Request.UserAgent.IndexOf("opera mini") > -1 || Request.UserAgent.IndexOf("blackberry") > -1 || Request.UserAgent.IndexOf("series60") > -1 || Request.UserAgent.IndexOf("series 60") > -1 || Request.UserAgent.IndexOf("palm") > -1 || Request.UserAgent.IndexOf("windows ce") > -1)
                return true;
            else
                return false;
        }

        public string CurrentUser
        {
            get {
                if (HttpContext.Current.User != null && HttpContext.Current.User.Identity != null && !string.IsNullOrEmpty(HttpContext.Current.User.Identity.Name) && HttpContext.Current.User.Identity.IsAuthenticated)
                    return HttpContext.Current.User.Identity.Name;
                else
                    return string.Empty;
            }
        }

        protected string ToJSON(int ret)
        {
            return "{\"result\":" + ret.ToString() + "}";
        }
        protected string ToJSON(string ret)
        {
            return "{\"result\":\"" + ret + "\"}";
        }
    }
}
